﻿using System;
using System.Windows;
using System.Windows.Controls;
using MyOS.Models;
using Panuon.UI.Silver;

namespace MyOS.Views.ChildView
{
    public partial class AttributeView : WindowX
    {
        private AttributeItemModel _attributeItemModel;
        private readonly byte[] attrBytes;
        private readonly string fileName;
        private StackPanel panel;
        private TextBlock txtheader;


        public AttributeView(string fileName, byte[] attrBytes)
        {
            InitializeComponent();
            Box.Header = fileName;
            this.fileName = fileName;
            this.attrBytes = attrBytes;
            getItemAttribute();
            DataContext = _attributeItemModel;
        }


        public void getItemAttribute()
        {
            _attributeItemModel = new AttributeItemModel {FileName = fileName};
            if (attrBytes[3] == 'e')
                _attributeItemModel.fileType = "文本文件";
            else if (attrBytes[3] == 'd') _attributeItemModel.fileType = "文件夹";

            switch (attrBytes[4])
            {
                case 0:
                    _attributeItemModel.canRead = false;
                    _attributeItemModel.canWrite = false;
                    break;
                case 1:
                    _attributeItemModel.canRead = true;
                    _attributeItemModel.canWrite = false;
                    break;
                case 2:
                    _attributeItemModel.canRead = false;
                    _attributeItemModel.canWrite = true;
                    break;
                case 3:
                    _attributeItemModel.canRead = true;
                    _attributeItemModel.canWrite = true;
                    break;
            }

            _attributeItemModel.StartBlock = attrBytes[5];
            var length = new byte[2];
            length[0] = attrBytes[6];
            length[1] = attrBytes[7];
            _attributeItemModel.Length = BitConverter.ToInt16(length);
            _attributeItemModel.createTime = (int) attrBytes[8] + "/" + (int) attrBytes[9] + "/" + (int) attrBytes[10] +
                                             " " + (int) attrBytes[11] + ":" + (int) attrBytes[12] + ":" +
                                             (int) attrBytes[13];
            _attributeItemModel.editTime = (int) attrBytes[14] + "/" + (int) attrBytes[15] + "/" + (int) attrBytes[16] +
                                           " " + (int) attrBytes[17] + ":" + (int) attrBytes[18] + ":" +
                                           (int) attrBytes[19];
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}